# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/" ;

global plusdir "R:/personlig/fenellac/stata_ado/plus/" ;
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Appendix B, Figure 1.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: April 30, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta" ;
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* FIGURE: menarche age and marriage age distribution
****************************************************************************** ;

* Full Sample  ;
twoway (kdensity menarche_age, bwidth(1))
(kdensity marriage_age, bwidth(1) lpattern(dash)),
legend(order(1 "Menarche" 2 "Marriage")) xtitle("Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-distributions-full.png", replace ;

* Rural ;
twoway (kdensity menarche_age if rural, bwidth(1))
(kdensity marriage_age if rural , bwidth(1) lpattern(dash)),
legend(order(1 "Menarche" 2 "Marriage")) xtitle("Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-distributions-rural.png", replace ;

* Urban ;
twoway (kdensity menarche_age if rural == 0, bwidth(1))
(kdensity marriage_age if rural == 0 , bwidth(1) lpattern(dash)),
legend(order(1 "Menarche" 2 "Marriage")) xtitle("Age") ytitle("Kernel Density") scheme(s2mono) ;  

graph export "./output/figure-distributions-urban.png", replace ;

****************************************************************************** ;
* LaTeX File for Figures
****************************************************************************** ;
shell echo \begin{figure} > "./output/figure-distributions.tex" ;

shell echo \caption{Distribution of Menarche Age and Marriage Age}\label{figure-distributions} >> "./output/figure-distributions.tex" ; 
shell echo \centering >> "./output/figure-distributions.tex" ;

shell echo \begin{subfigure}[b]{0.5\textwidth} >> "./output/figure-distributions.tex" ; 
shell echo \centering \includegraphics[width=\textwidth]{./analysis/output/figure-distributions-full.png} >> "./output/figure-distributions.tex" ;
shell echo \caption{Rural and Urban Women} >> "./output/figure-distributions.tex" ; 
shell echo \end{subfigure}\\ >> "./output/figure-distributions.tex" ; 

shell echo  \begin{subfigure}[b]{0.5\textwidth} >> "./output/figure-distributions.tex" ; 
shell echo \centering \includegraphics[width=\textwidth]{./analysis/output/figure-distributions-rural.png} >> "./output/figure-distributions.tex" ;
shell echo \caption{Rural Women} >> "./output/figure-distributions.tex" ; 
shell echo \end{subfigure}\\ >> "./output/figure-distributions.tex" ; 

shell echo  \begin{subfigure}[b]{0.5\textwidth} >> "./output/figure-distributions.tex" ; 
shell echo \centering \includegraphics[width=\textwidth]{./analysis/output/figure-distributions-urban.png} >> "./output/figure-distributions.tex" ;
shell echo \caption{Urban Women} >> "./output/figure-distributions.tex" ; 
shell echo \end{subfigure}\\ >> "./output/figure-distributions.tex" ; 

shell echo \captionsetup{justification=justified, width=\textwidth} >> "./output/figure-distributions.tex" ;
shell echo \caption*{\small \textit{Notes:} This figure plots the distribution
of menarche age and marriage age. Data from IHDS 2011-12. 
Epanechnikov kernel with bandwidth equal to one.} >> "./output/figure-distributions.tex" ;
shell echo \end{figure} >> "./output/figure-distributions.tex" ;


exit ;
